var config = require('../../config.js')
var http = require('../../utils/httpHelper.js')
Page({
  data: {
    teacher:{},
    allTeachers:[],
    sumPrice:0,
    timer:{},
    teacherPage:{
      current:1,
      pageSize:10,
			total:0
    }
  },
  onLoad: function () {
    var that = this;
    that.getAllTeachers(function(list){
      that.setData({allTeachers:list});
    })
  },
  onReachBottom(){
    if(this.timer != null){
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(()=>{
      this.getMoreData();
    },1000)
  },
  getMoreData() {
    var that = this;
    that.data.teacherPage.current++;
    that.getAllTeachers(function(list){
      let yList = that.data.allTeachers;
      yList = yList.concat(list);
      that.setData({allTeachers:yList});
    })
  },
  getAllTeachers:function (callback){
    var that = this;
    http.httpPost(config.clubApi.getTeacherList,{
      appid: config.APPID,
      pageNo:that.data.teacherPage.current,
      pageSize:that.data.teacherPage.pageSize,
      teacherType: '1'
    },function (res){
      if(res.code == '200'){
        var list = res.data.pageData;
        typeof callback == "function" && callback(list)
      }
    });
  },
  toDetail:function(e){
    var idParam = e.currentTarget.dataset.id;
    var idParamAry = idParam.split(',');
    if (idParamAry[2]>0) {
      wx.navigateTo({
        url: '../course/index?teacherId='+idParamAry[0]+'&teacherName='+idParamAry[1]
      })
    }else {
      wx.showToast({
        title: '没有课程可以展示',
        icon: 'success',
        duration: 1000
      });
    }
  },
  getTeacherInfo:function(id,callback){
    var data = {id:id}
    http.httpGet(config.clubApi.getTeacherInfo,data,function(res){
      if(res.code == '200'){
        var shop = res.data;
        typeof callback == "function" && callback(shop)
      }
    });
  }
})